from models.models_dev import OpOuterGoodsSkuLog as DevOpOuterGoodsSkuLog
from models.models_prod import OpOuterGoodsSkuLog as ProdOpOuterGoodsSkuLog
from services.base_dev_common_service import BaseDevCommonService
from utils.obj_utils import ObjectUtil


class DevOuterGoodsSkuLogService(BaseDevCommonService):
    def __init__(self):
        super().__init__(model_class=DevOpOuterGoodsSkuLog, time_field='create_time')

    def add(self, prod_orders: list[ProdOpOuterGoodsSkuLog], session=None):
        # 如果未提供session，则获取新的session
        if session is None:
            session = self.get_session()
        dev_orders = []
        for prod_order in prod_orders:
            dev_order = DevOpOuterGoodsSkuLog()
            ObjectUtil.copy_fields(dev_order, prod_order, self.get_table_fields({'id','online_minute'}))
            dev_orders.append(dev_order)
        session.add_all(dev_orders)
        session.commit()
